package com.thunbu.thunbu_meeting_system.activity

import android.content.Intent
import android.graphics.Color
import android.os.Handler
import com.cathu.lib_commonkt.base.BaseMVVMActivity
import com.thunbu.lib_common.R
import com.thunbu.thunbu_meeting_system.App
import com.thunbu.thunbu_meeting_system.MainActivity
import com.thunbu.thunbu_meeting_system.databinding.ActivitySplashBinding
import com.thunbu.thunbu_meeting_system.gotoActivity
import com.thunbu.thunbu_meeting_system.utils.AppUtils
import com.thunbu.thunbu_meeting_system.viewMdel.DefaultViewModel


/**
 *Created by Chaolue.Fan on 2021/5/13
描述:
 */
class SplashActivity : BaseMVVMActivity<ActivitySplashBinding, DefaultViewModel>() {
    override fun setStatusColor(): Int = Color.WHITE

    private var firstJumpCount = 1

    override fun onMVVMCreated() {
        Handler().postDelayed({
            if (firstJumpCount == 1)
                firstJumpCount++
            gotoNextAct()
        }, 500)

    }


    //考虑熄屏在回来或者切换
    override fun onResume() {
        super.onResume()
    }


    //同步取消注册
    override fun onPause() {
        super.onPause()



    }


//    // 网络监听
//    private val networkConnectionStatusBroadcastReceiver: BroadcastReceiver =
//        object : BroadcastReceiver() {
//            override fun onReceive(context: Context, intent: Intent) {
//                if (NetworkUtils.isNetworkAvailable(context)) {
//
//                    bindViews.linUnkownNetwork.visibility = View.GONE
//                    Handler().postDelayed({
//                        if (firstJumpCount == 1) {
//                            firstJumpCount++
//                            gotoNextAct()
//                        }
//                    }, 2000)
//                } else {
//                    bindViews.linUnkownNetwork.visibility = View.VISIBLE
//                }
//            }
//        }

//    override fun setContentId(): Int = R.layout.activity_splash


    private fun gotoNextAct() {

        if(!AppUtils.isAuthed()){
            gotoActivity<AuthorizationActivity> {  }
        }else
            if(AppUtils.isLogin()){
            gotoActivity<MainActivity> {  }
        }else{
            gotoActivity<LoginActivity> {  }
        }
//        startActivity(Intent(this,InventoryTaskListActivity::class.java))
//        startActivity(Intent(this,InventoryActivity::class.java))

        finish()
//        val code = MFSPHelper.getString(ThemeMeetingRoomActivity.CODETAG)
//        if (code.isNullOrEmpty()) {
//            gotoActivity<BindMeetingActivity>()
//        } else {
//            gotoActivity<ThemeMeetingRoomActivity> {
//                putExtra(ThemeMeetingRoomActivity.CODETAG, code)
//            }
//        }

    }
}